Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors channel failure tracking in ChannelPoolDpImpl by introducing a sessionEstablished flag to ensure that consecutive failures are only reset when a session is successfully opened or closed with an OK status, and incremented if a failure occurs before session establishment. A corresponding unit test has been added to verify this behavior. The review feedback correctly identifies a concurrency issue where sessionEstablished is read outside of a synchronized block but written inside one, and suggests declaring it as volatile to guarantee proper memory visibility.
| return new SessionStreamImpl(innerCall) { | ||
| // null until onBeforeSessionStart fires | ||
| @Nullable AfeId afeId = null; | ||
| boolean sessionEstablished = false; |
There was a problem hiding this comment.
The sessionEstablished field is read outside of a synchronized block in onMessage (line 332) but written inside a synchronized block (line 334). To ensure proper memory visibility and prevent thread-local caching or instruction reordering under the Java Memory Model (JMM), this field should be declared volatile.
| boolean sessionEstablished = false; | |
| volatile boolean sessionEstablished = false; |
References
- Ensure that fields used for cross-thread state checks, such as exceptions set by background threads and read by application threads, are declared as volatile to guarantee memory visibility and establish a proper happens-before relationship under the Java Memory Model.
d5c4ee1 to
b9617c3
Compare
b9617c3 to
c626c8b
Compare
Part 2 of 2 for b/584671437 (stacked on #15038).
What changed
ChannelPoolDpImplwhenOpenSessionResponsearrives (onMessage), rather than when initialPeerInfoheaders arrive (onBeforeSessionStart).OpenSessionResponseas consecutive failures and evict the failedrouteObservationsentry so subsequentOpenSessionattempts do not remain pinned to a failing AFE/subzone.